let nums = [2,2,1,1,1,2,2]
let majorityElement = function(nums){
    nums.sort((a, b) => a - b)
    let mid = Math.floor(nums.length / 2)
    return nums[mid]
}

console.log(majorityElement(nums))